// 变量基本类型

let num1: number = 0
let num2: BigInt = BigInt(0)

// num1 = num2 编译报错，因为number和BigInt不是同一个类型，BigInt表示任意大的数据，number的最大数是2^53 - 1，超过了这个数据就用BigInt表示

export function testSymbol() {
  let map: Object = {}
  let symbol = Symbol("testSymbol")
  map[symbol] = "value is testSymbol"
  map["test"] = 0
  console.log("testSymbol", map[symbol])
  console.log("testMap", map["test"])
  testMapNum(map["test"])
}


function testMapNum(num: number) {
  console.log("testMapNum", num)
}

// 04-18 07:41:09.934 21447-4031/com.example.harmonystudy I 0FEFE/JsApp: testObject1 [object Object]
// 04-18 07:41:09.934 21447-4031/com.example.harmonystudy I 0FEFE/JsApp: testObjectName Alice

export function testObject() {
  let obj: Object;
  obj = { name: 'Alice', age: 10 };
  let name = obj["name"]
  console.log("testObject1", obj.toString())
  console.log("testObjectName", name)
  obj = 0
  console.log("testObjectNumber", obj)

  // let obj1: object = 1 编译会报错，object不能表示基本类型数据

}

/**
 * literal: 字面量
 */
export function testLiteral() {
  let literalStr: 'literal' | 'test'
  literalStr = 'literal'
  literalStr = 'test'
  //literalStr = "other" 编译报错，literalStr只能是literal或者test

  var { x: y = 3 } = { x: 5 };
}


type Easing = 'ease-in' | 'ease-out' | 'ease-in-out'


type ColorStr = 'RED' | 'BLUE' | 'WHITE'

export function giveColor(colorStr: ColorStr) {
  console.log("giveColor", colorStr)
}

type RequestResult = {
  isSuccess: true,
  msg: "success",
  code: 200
} | {
  isSuccess: false,
  msg: string,
  code: number
}

export function testLiteralBoolean() {
  let failResult: RequestResult = { isSuccess: false, msg: "connect error", code: 3000 }
  let successResult: RequestResult = {
    isSuccess: true,
    msg: "success",
    code: 200
  }

  console.log("testLiteralBoolean success", successResult.isSuccess)
  console.log("testLiteralBoolean fail", failResult.isSuccess)

}

export function testTypeOf() {
  let obj: object = {}
  let objType = typeof obj
  if (objType === 'object') {
    console.log("testTypeOf", "typeOf can use object1")
  }
  switch (objType) {
    case 'object':
      console.log("testTypeOf", "typeOf can use object2")
      break;
  }
}